<template>
    <Sider style="background:#fff;border-right:1px solid #dcdee2;padding:10px">
        <Tree :data="newsCate" @on-select-change="getNews" ></Tree>
    </Sider>
    
</template>
<script>
    import { mapActions } from 'vuex';
    export default {
        data () {
            return {
                host:"http://10.31.156.62:3000",
                newsCate: []
            }
        },
        methods:{
            ...mapActions([
                'changePage',
                'changeLimit',
                'changeTotal',
                'changeNews',
                'changeNodeSelected'
            ]),
            getNews(nodeArr){
                if(nodeArr!=''){
                    this.axios({
                        url:`${this.host}/news/list`,
                        method:'post',
                        data:{
                            belong:nodeArr[0]._id
                        }
                    }).then(res=>{
                        //console.log(nodeArr)
                        this.changePage(1)
                        this.changeLimit(10)
                        this.changeTotal(res.data.total)
                        res.data.rows.forEach(value=>{
                            if(value.pushtime){
                                value.pushtime=value.pushtime.moment()
                            }
                        })
                        this.changeNews(res.data.rows)
                        //console.log(res.data.rows)
                        this.changeNodeSelected(nodeArr[0])
                    })
                }
            }
        },
        mounted(){
            this.axios({
                url:`${this.host}/cate/list/1`,
                method:'post'
            }).then(res=>{
                this.newsCate=res.data
            })
        }
    }
</script>

